package com.cwk.yygh.hosp.controller;


import com.cwk.yygh.common.result.Result;
import com.cwk.yygh.hosp.service.HospitalSetService;
import com.cwk.yygh.model.hosp.HospitalSet;
import com.cwk.yygh.vo.hosp.HospitalSetQueryVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/hosp/hospitalSet")
@RequiredArgsConstructor
public class HospitalSetController {
    private final HospitalSetService hospitalSetService;

    //增删改查

    //查询所有医院设置
    @GetMapping(value ="findAll")
    public Result findAllHospitalSet() {
        List<HospitalSet> list = hospitalSetService.list();
        return Result.ok(list);
    }
    //删除医院设置
    @DeleteMapping("{id}")
    public Result removeHospitalSet(@PathVariable Long id){
        boolean b = hospitalSetService.removeById(id);
        if(b){
            return Result.ok();
        }

        return Result.fail();
    }
    //医院设置添加
    @PostMapping("saveHospitalSet")
    public Result saveHospitalSet(@RequestBody HospitalSet hospitalSet){
        boolean save = hospitalSetService.saveHospitalSet(hospitalSet);
        if(save){
            return Result.ok();
        }
        return Result.fail();
    }
    //分页查询
    @PostMapping("findPageHospSet/{current}/{limit}")
    public Result findPageHospitalSet(@PathVariable Long current,
                                      @PathVariable Long limit,
                                      @RequestBody(required = false) HospitalSetQueryVo hospitalSetQueryVo){
        return Result.ok(hospitalSetService.findPageHospitalSet(current, limit,hospitalSetQueryVo));
    }
    //通过医院Id查找医院信息
    @GetMapping("getHospSet/{id}")
    public Result getHospSet(@PathVariable Long id){
        HospitalSet hospitalSet = hospitalSetService.getById(id);
        return Result.ok(hospitalSet);
    }
    //医院更新
    @PostMapping("updateHospSet")
    public Result updateHospSet(@RequestBody HospitalSet hospitalSet){
        boolean b = hospitalSetService.updateById(hospitalSet);
        if(b){
            return Result.ok();
        }
        return Result.fail();
    }
    // 批量删除
    @DeleteMapping("batchRemove")
    public Result batchRemoveHospSet(@RequestBody List<Long> idList){
        hospitalSetService.removeByIds(idList);
        return Result.ok();
    }
    // 锁定修改
    @PutMapping("lockHospSet/{id}/{status}")
    public Result lockHospSet(@PathVariable Long id,@PathVariable Integer status){
        hospitalSetService.lockHospSet(id, status);
        return Result.ok();
    }
    // 发送签名秘钥
    @GetMapping("sendKey/{id}")
    public Result sendKey(@PathVariable Long id){
        HospitalSet hospitalSet = hospitalSetService.getById(id);
        String signKey = hospitalSet.getSignKey();
        String hoscode = hospitalSet.getHoscode();
        //TODO 发送短信
        return Result.ok();
    }

}
